from django import forms


class LoginForm(forms.Form):
    username = forms.CharField()
    password = forms.CharField(widget=forms.PasswordInput(attrs=({"placeholder":u"请输入密码"})))
class RegisterForm(forms.Form):
    username = forms.CharField()
    password = forms.CharField(
        max_length=8,
        #min_length = 6,
        widget=forms.PasswordInput(attrs=({"placeholder": u"请输入密码"})),
        error_messages={'min_length':u'密码长度小于6'}
                               )
    password_repeat = forms.CharField(widget=forms.PasswordInput(attrs=({"placeholder": u"请输入密码"})))
    email = forms.EmailField()

    #def clean_password(self):
    #    password = self.cleaned_data.get("password")
    #    if len(password)<6:
    #        raise forms.ValidationError(u'密码小于6')

    def clean(self):
        super(RegisterForm,self).clean()
        password = self.cleaned_data.get("password")
        password_repeat = self.cleaned_data.get("password_repeat")
        if str(password) != str(password_repeat):
            #raise forms.ValidationError(u'两次输入密码不一样')
            self.add_error('password',u'密码不相等')
        self.cleaned_data